$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'vipuser/vipinfos/list?audit=true',
        datatype: "json",
        colModel: [
            { label: 'vipID', name: 'vipinfoid', index: 'VipInfoId',key:true, width: 40},
            { label: '用户ID', name: 'userinfoid', index: 'UserInfoId', width: 80 },
            { label: '用户账户', name: 'useraccount', index: 'UserAccount', width: 80 },
            { label: '用户名', name: 'username', index: 'UserName', width: 80 },
            { label: '性别', name: 'usergender', index: 'UserGender',align:"center", width: 40,formatter: function(value, options, row){
                    return value === 0 ? '男' : '女';
                } },
            { label: '手机号码', name: 'phonenum', index: 'PhoneNum', width: 80 },
            { label: '会员申请价格', name: 'priceinvip', index: 'PriceInVip', width: 80,formatoptions:{decimalSeparator:".", thousandsSeparator: " ", decimalPlaces: 2, defaulValue: 0},formatter:'integer' },
            { label: '处理人', name: 'dealusername', index: 'DealUserName', width: 60 },
            { label: '创建时间', name: 'createtime', index: 'CreateTime', width: 90 },
            { label: '过期时间', name: 'expirationtime', index: 'ExpirationTime', width: 90 },
            { label: '审核状态', name: 'auditstatus', index: 'AuditStatus', width: 80 ,formatter: function(value, options, row){
                    var status = null;
                    if (value === 0){
                        status = '<span class=".label label-warning">待审核</span>';
                    }else if(value === 1){
                        status = '<span class="label label-success">审核通过</span>';
                    }else if (value === 2){
                        status = '<span class="label label-danger">审核失败</span>';
                    }else{
                        status = '<span class="label label-danger">错误</span>';
                    }
                    return status;
                }},
            { label: '审核状态时间', name: 'auditdate', index: 'AuditDate', width: 90 }
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		vipinfos: {},
        searchParam:null
	},
	methods: {
		query: function () {
			vm.reload();
		},
		update: function (event) {
			var vipinfoid = getSelectedRow();
			if(vipinfoid == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";

            vm.getInfo(vipinfoid)
		},
		updateRequest: function (event) {
			$.ajax({
				type: "POST",
			    url: baseURL + "vipuser/vipinfos/vipauditUpdate",
                contentType: "application/json",
			    data: JSON.stringify(vm.vipinfos),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		getInfo: function(vipinfoid){
			$.get(baseURL + "vipuser/vipinfos/info/"+vipinfoid, function(r){
                vm.vipinfos = r.vipinfos;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{
                page:page
            }).trigger("reloadGrid");
		},
        reason:function(){
            if(this.vipinfos == null){
                return false;
            }
            //审核状态当前为不同就显示
            if(this.vipinfos.auditstatus == 2){
                return true;
            }
            //审核状态为待审核，且有原因就显示
            if(this.vipinfos.auditstatus == 0 && this.vipinfos.cannotpassreason != null && this.vipinfos.cannotpassreason != ""){
                return true;
            }
            return false;
        }
	}
});